//shmadd.c
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#include <stdlib.h>

#define BUFSZ 2048

int main(void)
{
	int shmid;
	char *shmaddr;
	//Create shared memory
	if((shmmid = shmget(IPC_PRIVATE, BUFSZ, 0666)) < 0)
	{
		perror("shmget error");
		exit(1);
	}
	else
	{
		printf("created shared-memory:%d\n", shmid);
	}
	system("ipcs -m");
	//Reflecte shered memory
	if((shmaddr = shmat(shmid, 0, 0)) < (char *)0)
	{
		perror("shmat error");
		exit(1);
	}
	else
	{
		printf("attached shared memory\n");
	}
	//display the system memory
	system("ipcs -m");
	//delete the shared memory
	if((shmdt(shmaddr)) < 0)
	{
		perror("shmdt error");
		exit(1);
	}
	else
	{
		printf("deleted shared memory\n");
		
	}
	
	system("ipcs -m");
	exit(0);
	
	
	
	
	
	
	
}	